package com.wswy.wyjk.ui.main.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wswy.wyjk.R;

import com.wswy.wyjk.ui.main.model.RankResponse;
import com.wswy.wyjk.utils.GlideUtils;
import com.wswy.wyjk.utils.Tools;

public class RankAdapter extends BaseQuickAdapter<RankResponse.ListBean, BaseViewHolder> {

    public RankAdapter() {
        super(R.layout.layout_item_rank);
    }

    @Override
    protected void convert(BaseViewHolder viewHolder, RankResponse.ListBean listBean) {
        viewHolder.setText(R.id.tv_name, listBean.getUser().getNickname())
                .setText(R.id.tv_time, "用时: "+ Tools.formatSecondTime(listBean.getDuration()))
                .setText(R.id.tv_score, listBean.getScore()+"分");

        GlideUtils.load(mContext, listBean.getUser().getAvatar(), viewHolder.getView(R.id.iv_head),R.drawable.avatar_default, true);

        viewHolder.setVisible(R.id.iv_rank, true);
        viewHolder.setText(R.id.tv_rank, "");
        viewHolder.setTextColor(R.id.tv_time, mContext.getResources().getColor(R.color.textColorWrong));
        viewHolder.setTextColor(R.id.tv_score, mContext.getResources().getColor(R.color.textColorWrong));
        if (viewHolder.getAdapterPosition() == 0) {
            viewHolder.setImageResource(R.id.iv_rank, R.drawable.rank_1);
        } else if (viewHolder.getAdapterPosition() == 1) {
            viewHolder.setImageResource(R.id.iv_rank, R.drawable.rank_2);
        } else if (viewHolder.getAdapterPosition() == 2) {
            viewHolder.setImageResource(R.id.iv_rank, R.drawable.rank_3);
        } else {
            viewHolder.setVisible(R.id.iv_rank, false);
            viewHolder.setText(R.id.tv_rank, viewHolder.getAdapterPosition() + 1+"");
            viewHolder.setTextColor(R.id.tv_time, mContext.getResources().getColor(R.color.color_808080));
            viewHolder.setTextColor(R.id.tv_score, mContext.getResources().getColor(R.color.blue));
        }
    }
}
